import {userRequest} from '@/utils/request'
enum API {
    GET_ROLELIST = '/admin/acl/role',
    ADD_ROLE = '/admin/acl/role/save',
    UPDATE_ROLE = '/admin/acl/role/update',
    DELETE_ROLE = '/admin/acl/role/remove',
    GET_ROLE = '/admin/acl/role/toAssign',
    ASSIGN_PERMISSION = '/admin/acl/role/doAssign',
    BATCH_DELETE = '/admin/acl/role/batchRemove',
    GET_PERMISSION = '/admin/acl/permission/toAssign',
    GET_ALL_PERMISSION = '/admin/acl/permission',
    ASSIGN_PERMISSION_TO_ROLE = '/admin/acl/permission/doAssign',
}

export const reqGetRoleList = (page: number, limit: number, roleName: string) =>
    userRequest.get<any, any>(API.GET_ROLELIST + `/${page}/${limit}?roleName=${roleName}`)
export const reqAddRole = (data: any) =>
    userRequest.post<any, any>(API.ADD_ROLE, data)
export const reqUpdateRole = (data: any) =>
    userRequest.put<any, any>(API.UPDATE_ROLE, data)
export const reqDeleteRole = (id: number) =>
    userRequest.delete<any, any>(API.DELETE_ROLE + `/${id}`)
export const reqGetRole = (roleId: number) =>
    userRequest.get<any, any>(API.GET_ROLE + `/${roleId}`)
export const reqAssignPermission = (data: any) =>
    userRequest.post<any, any>(API.ASSIGN_PERMISSION, data) 
export const reqGetPermission = (roleId: number) =>
    userRequest.get<any, any>(API.GET_PERMISSION + `/${roleId}`)
// export const reqAssignRole = (data: any) =>
//     userRequest.post<any, any>(API.ASSIGN_ROLE, data)
export const reqAssignPermissionToRole = (roleId: any,permissionId:any) =>
    userRequest.post<any, any>(API.ASSIGN_PERMISSION_TO_ROLE + `?roleId=${roleId}&permissionId=${permissionId}`)
export const reqGetRoleListByUserId = (userId: number) =>
    userRequest.get<any, any>(API.GET_ROLELIST + `/${userId}`)
export const reqBatchDelete = (data: any) =>
    userRequest.delete<any, any>(API.BATCH_DELETE, { data })
export const reqGetAllPermission = () =>
    userRequest.get<any, any>(API.GET_ALL_PERMISSION)